<?php
$db = new MySQL();
if ($_SESSION['permission']) {
    ?>

    <?php
    $paging = new paging();
    $curpg = $_GET['curpg'];
    $curpg = (isset($curpg)) ? $curpg : 1;
    $mod = $_GET['mod'];
    $gotopage = "?mod=" . $mod . "&act=list";

    $query = "select * from account order by id";
    $totalrows = find($query, 'count');

    $query = "select * from account order by id limit " . (($curpg - 1) * $perpage) . ", " . $perpage;
    $items = find($query);
    require_once 'include/js_for_list.php';
    ?>

    <div class="page-header">
        <div class="pull-left">Account</div>
        <div class="pull-right"></div>
        <div class="clear"></div>
    </div>

    <form name="frmlist" method="post" action="" editurl="?mod=<?= $mod ?>&act=edit" delurl="?mod=<?= $mod ?>&act=process" >
        <div class="pull-right">
            <button onclick="add(this);" type="button" class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-plus"></span>Add</button>
            <button onclick="delall(this);" type="button" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-remove"></span>Delete</button>
        </div>
        <div class="clear"/>
        <table class="table">
            <thead>
                <tr>
                    <th><input type="checkbox" class="checkall"></th>
                    <th>Username</th>
                    <th>Email</th>
                    <th width="70">Action</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($totalrows != 0) : ?>
                    <?php foreach ($items as $key => $row) : ?>
                        <tr rowid="<?= $row["id"] ?>">
                            <td ><input type="checkbox" name="chkid" value="<?= $row["id"] ?>" /></td>
                            <td ><?= $row["username"] ?></td>
                            <td ><?= $row["email"] ?></td>
                            <td >
                                <a href="javascript:void(0);" onclick="edit('<?= $row["id"] ?>')"><span class="glyphicon glyphicon-edit"></span></a> &nbsp; 
                                <a href="javascript:void(0)" onclick="del('<?= $row["id"] ?>')"><span class="glyphicon glyphicon-remove"></span></a> 
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
        <table width="100%" border="0" cellspacing="0">										
            <tr>
                <td colspan="2" align="left" valign="middle" class="titlepage"><?= $lb_tottalrow ?>  <span class="numpage"><?= $totalrows ?></span> </td>
                <td colspan="3" align="right" valign="top" class="numpage"><?php echo $paging->pagenew($totalrows, $perpage, $pagecount, $curpg, $gotopage, "", "titlepage"); ?> </td>
            </tr>

        </table>

        <input type="hidden" id="form_" name="form_" value="delete" />		
        <input type="hidden" id="listid" name="listid" value="" />
        <input type="hidden" id="curpg" name="curpg" value="<?= $curpg ?>" />
    </form>		

    <?php
}
else {
    echo " You not permission to access this page.";
}
$db->close();
?>
